package com.chanyachting.emall.domain;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.chanyachting.emall.dao.MemberorderservicesDAO;
import com.chanyachting.emall.domain.base.BaseMemberorderservices;
import com.chanyachting.emall.util.DateUtil;

/**
 * This is the object class that relates to the memberorderservices table.
 * Any customizations belong here.
 */
public class Memberorderservices extends BaseMemberorderservices {

/*[CONSTRUCTOR MARKER BEGIN]*/
	public Memberorderservices () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public Memberorderservices (java.lang.Integer _id) {
		super(_id);
		
		Memberorderservices ms=(Memberorderservices)new MemberorderservicesDAO().load(Memberorderservices.class, _id);
		
		if(ms!=null){
			
			try {
				BeanUtils.copyProperties(this, ms);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * Constructor for required fields
	 */
	public Memberorderservices (
		java.lang.Integer _id,
		java.lang.Integer _serviceId,
		java.lang.String _nowState,
		java.lang.Integer _memberId,
		java.lang.Integer _serviceMonthLimit,
		java.lang.Integer _serviceExecuteTime,
		java.lang.String _serviceOptionType,
		java.math.BigDecimal _servicePrice,
		java.lang.String _serviceName,
		java.lang.String _orderDate) {

		super (
			_id,
			_serviceId,
			_nowState,
			_memberId,
			_serviceMonthLimit,
			_serviceExecuteTime,
			_serviceOptionType,
			_servicePrice,
			_serviceName,
			_orderDate);
	}
/*[CONSTRUCTOR MARKER END]*/
	
	public Memberorderservices(Member member,Emallservices es){
		
		this.setServiceId(es.getId());
		this.setNowState("00");				//当前状态，默认为无效
		this.setMemberId(member.getId());
		
		this.setMemberEmail(member.getEmail());
		this.setMemberPhone("");
		
		this.setServiceMonthLimit(es.getMonthLimit());
		this.setServiceExecuteTime(0);   //功能执行次数，默认0
		this.setServiceOptionType(es.getOptionType());
		this.setServicePrice(es.getServicePrice());
		this.setServiceName(es.getServiceName());
		
		this.setServiceSummary(es.getSummary());
		this.setServiceLimitTime(es.getLimitTime());
		this.setServiceId(es.getId());
		
		this.setIfLimitTime(es.getIfLimitTime());
		
		this.setOrderDate(DateUtil.getDate()); //记录创建时间
		
	}
	
	
	/**
	 * 会员指定操作类型，有效的功能服务列表
	 * @param memberId
	 * @param serviceOptionType
	 * @return
	 */
	public static List listByOptionTypeAndActivityAndMemberId(int memberId,String serviceOptionType){
		
		String args[]={String.valueOf(memberId),serviceOptionType};
		
		return new MemberorderservicesDAO().find("from Memberorderservices where memberId=? and nowState='01' and serviceOptionType=? ",args);
		
	}
	
	
	
	public static List listByMemberId(int memberId){
		
		
		String args[]={String.valueOf(memberId)};
		
		return new MemberorderservicesDAO().find("from Memberorderservices where memberId=?",args);
	}
	
	
	
	public static List list(){
		
		return new MemberorderservicesDAO().find("from Memberorderservices");
	}
	
	
	
	
	
	
	public boolean save(){

		new MemberorderservicesDAO().save(this);
		
		return true;
	}
	
	
	public boolean update(){
		
		new MemberorderservicesDAO().update(this);
		
		return true;
	}
	
	
	public boolean delete(){
		
		new MemberorderservicesDAO().delete(this);
		
		return true;
	}
}